カラーパレット

library(spdep)
## Loading required package: sp
## Loading required package: boot
## Loading required package: Matrix
## Loading required package: lattice
## 
## Attaching package: 'lattice'
## 
## The following object(s) are masked from 'package:boot':
## 
##     melanoma
## 
## Loading required package: MASS
## Loading required package: nlme
## Loading required package: maptools
## Loading required package: foreign
## Checking rgeos availability: TRUE
## Loading required package: deldir
## deldir 0.0-19
## 
##      PLEASE NOTE:  The components "delsgs" and "summary" of the 
##      object returned by deldir() are now DATA FRAMES rather than 
##      matrices (as they were prior to release 0.0-18). 
##      See help("deldir").
##  
##      PLEASE NOTE: The process for determining duplicated points
##      has changed from that used in version 0.0-9 (and previously).
## 
## Loading required package: coda
library(classInt)
## Loading required package: class
## Loading required package: e1071
# コロンバス市の犯罪発生データ
d <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1])
# 白地図の表示
plot(d)

plot of chunk r13


# カラーパレット(白→赤)の作成
pal <- c("white","red")
cls1 <- classIntervals(d$CRIME, n=5, style="quantile") # 等量分類
cls2 <- classIntervals(d$CRIME, n=5, style="equal") # 等間隔分類
cls3 <- classIntervals(d$CRIME, n=5, style="sd") # 標準偏差分類
cls4 <- classIntervals(d$CRIME, n=5, style="fisher") # 自然階級分類
cls5 <- classIntervals(d$CRIME, n=5, style="pretty") # 視覚的に分かりやすい分類
cls6 <- classIntervals(d$CRIME, n=5, style="kmeans") # 非階層クラスタリングによる分類
cls7 <- classIntervals(d$CRIME, n=5, style="hclust") # 階層クラスタリングによる分類
par(mfrow=c(2,4))
plot(cls1, pal=pal, main="quantile")
plot(cls2, pal=pal, main="equal")
plot(cls3, pal=pal, main="sd")
plot(cls4, pal=pal, main="fisher")
plot(cls5, pal=pal, main="pretty")
plot(cls6, pal=pal, main="kmeans")
plot(cls7, pal=pal, main="hclust")

plot of chunk r13


# 塗分け方の指定
color.pal <- findColours(cls1, pal)
# 塗分け地図の作成
par(mfrow=c(1,1))
plot(d, col=color.pal)
title(main="quantile")
legend("topleft", fill=attr(color.pal, "palette"),
legend=names(attr(color.pal,"table")),bty="n")

plot of chunk r13